import React from 'react';
import { Redirect } from 'umi';
import { getRouteAuth } from '@/utils/utils';

const defaultAuthMenu = [
  {
    path: '/',
    name: '首页',
  },
  {
    path: '/403',
    name: '页面未授权',
  },
  {
    path: '/404',
    name: '页面未找到',
  },
  {
    path: '/500',
    name: '服务器错误',
  },
  {
    path: '/messageCenter',
    name: '消息中心',
  },
  {
    path: '/barChartCenter',
    name: '数据中心',
  },
];

const Authorized = props => {
  const { children, pathname, menuData } = props;
  const auth = getRouteAuth(pathname, defaultAuthMenu.concat(menuData));
  if (auth) {
    return children;
  } else {
    return <Redirect to="/404" />;
  }
};

export default Authorized;
